package controller;

import impl.service.UserSql;
import model.ResponseBodyMessage;
import model.User;

import java.sql.SQLException;

public class UserController {
    private final static UserSql USER_SQL = new UserSql();
    public ResponseBodyMessage<Integer> login(String username, String password){
        try {
            System.out.println("查询账户");
            User user = USER_SQL.userToPassword(username);
            System.out.println("查询成功");

            if (user == null){
                return new ResponseBodyMessage<>(false,"没有该账户",-1);
            }
            if (password.equals(user.getPassword())){
                return new ResponseBodyMessage<>(true,"登录成功",user.getId());
            }
            return new ResponseBodyMessage<>(false,"密码错误",-1);
        } catch (SQLException e) {
            System.out.println("查询失败");
            throw new RuntimeException(e);
        }
    }
    public ResponseBodyMessage<Integer> sign(String username,String password){
        try {
            return USER_SQL.sign(username,password);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
